# 文件打开open（）,encoding=utf-8
# open()打开得到的是一个文件对象
# 读取文件内容
f = open(r'C:\Users\Administrator\Desktop\222.txt', encoding='utf-8')
print(f.read())
# 使用with open读取文件
with open(r'C:\Users\Administrator\Desktop\222.txt',encoding='utf-8') as file:
    text = file.read()
    print(text)


# 写文件write()
data = 'hello world'
f1 = open('111.txt','w',encoding='utf-8')
f1.write('Helloween. Helloween')
f1.close()

#打开文件用于写入，如果文件不存在将会被创建
with open('111.txt','w',encoding='utf-8') as file:
    file.write(data)